package com.atguigu.aopanno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

//抽取相同的切入点
@Component
@Aspect
public class PointProxy {

    //相同切入点抽取
    @Pointcut(value = "execution(* com.atguigu.aopanno.User.addPoint(..))")
    public void pointdemo() {}


    //在此增强类中,不同的方法,代表不同的通知类型

    //前置通知
    //@Before注解表示作为前置通知
    @Before(value = "pointdemo()")
    public void before() {
        System.out.println("before......");
    }

    //最终通知(返回通知,当有异常就不执行)
    @AfterReturning(value = "pointdemo()")
    public void afterReturning() {
        System.out.println("afterReturning ........");
    }

    //后置通知(最终通知,有无异常都会执行)
    @After(value = "pointdemo()")
    public void after() {
        System.out.println("after......");
    }

    //异常通知(当被代理的方法存在异常,此通知才会执行)
    @AfterThrowing(value = "pointdemo()")
    public void afterThrowing() {
        System.out.println("afterThrowing........");
    }

    //环绕通知
    //会在被增强的方法之前和之后都执行
    @Around(value = "pointdemo()")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕之前........");
        //被增强的方法执行
        proceedingJoinPoint.proceed();
        System.out.println("环绕之后........");
    }

}
